//app.js
App({
  onLaunch: function () {
    //this.login()
  },
  login: function (cb) {
    var _that = this
    wx.login({
      success: function (lres) {
        if (lres.code) {
          wx.request({
            url: _that.config.apiurl + "api/user/login",
            data: { code: lres.code },
            method: 'POST',
            success: function (res) {
              wx.setStorageSync('token', res.data.result.token)
              cb(res.data.result.user)
            },
            fail: function (res) { },
            complete: function (res) { },
          })

        } else {
          _that.toast("登录失败，请重新打开小程序")
        }
      }
    });
  }
  , toast: function (message,time,cb) {
    if(time==null){
      time=2000;
    }
    wx.showToast({
      title: message,
      icon: "none",
      duration: time
    })
    if(cb!=null){
      setTimeout(cb,time)
    }
  }
  , globalData: {
    userInfo: null
    , locationInfo: null
  },
  config: {
    apiurl: "https://yueyixing.beiyii.xyz/",
    resurl: "http://res.beiyii.com/"
  },
  user_time:null
})